import 'package:bloc/bloc.dart';
import 'package:word_range_client/pojo/vo/UserVo.dart';

import '../viewModels/UserViewModel.dart';

// 定义事件
abstract class UserEvent {}

class LoadUser extends UserEvent {}

// 定义状态
abstract class UserState {}

class UserLoading extends UserState {}

class UserLoaded extends UserState {
  final UserViewModel userViewModel;

  UserLoaded(this.userViewModel);
}

// 创建 Bloc
class UserBloc extends Bloc<UserEvent, UserState> {
  UserBloc() : super(UserLoading()) {
    on<LoadUser>((event, emit) async {
      final userViewModel = UserViewModel();
      await userViewModel.initializeCurrentUser(); // 确保等待异步操作完成
      emit(UserLoaded(userViewModel));
    });
  }
}
